#-------------------------------------------------------------------
# This file is part of the CMake build system for ogre-aml (Advanced mesh loader for Ogre 3D)
#-------------------------------------------------------------------

# copy one file
macro (copy_dep_files FILEPREFIX INPUT)
	if (WIN32)
		set (INPUTFILE ${INPUT}.dll)
	else ()
		set (INPUTFILE ${INPUT})
	endif (WIN32)

	if (EXISTS ${SETUP_OGRE_BUILD_PATH}/bin/${FILEPREFIX}/${INPUTFILE})
		configure_file (${SETUP_OGRE_BUILD_PATH}/bin/${FILEPREFIX}/${INPUTFILE} ${CMAKE_BINARY_DIR}/bin/${FILEPREFIX}/${INPUTFILE} COPYONLY)
	endif (EXISTS ${SETUP_OGRE_BUILD_PATH}/bin/${FILEPREFIX}/${INPUTFILE})
endmacro (copy_dep_files FILEPREFIX INPUTFILE)

# copy files
macro (copy_dep INPUT)
	copy_dep_files (release ${INPUT})
	copy_dep_files (relwithdebinfo ${INPUT})
	copy_dep_files (minsizerel ${INPUT})
	copy_dep_files (debug "${INPUT}_d")
endmacro (copy_dep INPUT)

# copy ogre component
macro (copy_ogre_component COMPONENT)
	message (STATUS "Looking for ${COMPONENT}...")
	# check component 
	if (OGRE_${COMPONENT}_FOUND)
		message (STATUS "${COMPONENT} found")
		
		#copy release library
		if (EXISTS ${OGRE_${COMPONENT}_REL})
			message (STATUS "  Coping ${OGRE_${COMPONENT}_REL}...")
			# copy to release dir
			message (STATUS "    coping to " ${CMAKE_BINARY_DIR}/bin/release/)
			configure_file (${OGRE_${COMPONENT}_REL} ${CMAKE_BINARY_DIR}/bin/release/ COPYONLY)
			# copy to relwithdebinfo dir
			message (STATUS "    coping to " ${CMAKE_BINARY_DIR}/bin/relwithdebinfo/)
			configure_file (${OGRE_${COMPONENT}_REL} ${CMAKE_BINARY_DIR}/bin/relwithdebinfo/ COPYONLY)
			# copy to minsizerel dir
			message (STATUS "    coping to " ${CMAKE_BINARY_DIR}/bin/minsizerel/)
			configure_file (${OGRE_${COMPONENT}_REL} ${CMAKE_BINARY_DIR}/bin/minsizerel/ COPYONLY)
			# set libdrary avaible flag
			set (OGRE_${COMPONENT}_REL_AVAILABLE TRUE)
		endif (EXISTS ${OGRE_${COMPONENT}_REL})
		
		#copy debug library
		if (EXISTS ${OGRE_${COMPONENT}_DBG})
			message (STATUS "  Coping ${OGRE_${COMPONENT}_DBG}...")
			message (STATUS "    coping to " ${CMAKE_BINARY_DIR}/bin/debugs/)
			configure_file (${OGRE_${COMPONENT}_DBG} ${CMAKE_BINARY_DIR}/bin/debug/ COPYONLY)
			# set libdrary avaible flag
			set (OGRE_${COMPONENT}_DBG_AVAILABLE TRUE)
		endif (EXISTS ${OGRE_${COMPONENT}_DBG})
	else ()
		message (STATUS "${COMPONENT} not found")
	endif (OGRE_${COMPONENT}_FOUND)
endmacro (copy_ogre_component COMPONENT)

# implementation of validating ogre components
macro (comment_ogre_component_impl COMPONENT_SUFFIX COMPONENT_NAME)
	if (OGRE_${COMPONENT_NAME}_${COMPONENT_SUFFIX}_AVAILABLE)
		set (COMMENT_${COMPONENT_NAME}_${COMPONENT_SUFFIX} "")
	else ()
		set (COMMENT_${COMPONENT_NAME}_${COMPONENT_SUFFIX} "#")
	endif (OGRE_${COMPONENT_NAME}_${COMPONENT_SUFFIX}_AVAILABLE)
endmacro (comment_ogre_component_impl COMPONENT_SUFFIX COMPONENT_NAME)

# validating ogre components
macro (comment_ogre_component COMPONENT)
	comment_ogre_component_impl(REL ${COMPONENT})
	comment_ogre_component_impl(DBG ${COMPONENT})
endmacro (comment_ogre_component COMPONENT)

# creating configuration files
macro (aml_create_config PREFIX_CFG SUFFIX_CFG)
	set(DEBUG_CFG_NAME ${PREFIX_CFG}_d${SUFFIX_CFG})
	set(RELEASE_CFG_NAME ${PREFIX_CFG}${SUFFIX_CFG})
	if (WIN32)
		# create debug file
		message (STATUS "Creating " ${DEBUG_CFG_NAME}...)
		configure_file(${CMAKE_HOME_DIRECTORY}/CMake/Templates/${DEBUG_CFG_NAME}.in ${CMAKE_BINARY_DIR}/bin/debug/${DEBUG_CFG_NAME})

		# create release file
		message (STATUS "Creating " ${RELEASE_CFG_NAME}...)
		configure_file(${CMAKE_HOME_DIRECTORY}/CMake/Templates/${RELEASE_CFG_NAME}.in ${CMAKE_BINARY_DIR}/bin/release/${RELEASE_CFG_NAME})
		configure_file(${CMAKE_HOME_DIRECTORY}/CMake/Templates/${RELEASE_CFG_NAME}.in ${CMAKE_BINARY_DIR}/bin/relwithdebinfo/${RELEASE_CFG_NAME})
		configure_file(${CMAKE_HOME_DIRECTORY}/CMake/Templates/${RELEASE_CFG_NAME}.in ${CMAKE_BINARY_DIR}/bin/minsizerel/${RELEASE_CFG_NAME})
	elseif (UNIX)
		if (CMAKE_BUILD_TYPE STREQUAL "debug")
			# create debug file
			message (STATUS "Creating " ${DEBUG_CFG_NAME}...)
			configure_file(${CMAKE_HOME_DIRECTORY}/CMake/Templates/${DEBUG_CFG_NAME}.in ${CMAKE_BINARY_DIR}/bin/${DEBUG_CFG_NAME})
		else ()
			# create release file
			message (STATUS "Creating " ${RELEASE_CFG_NAME}...)
			configure_file(${CMAKE_HOME_DIRECTORY}/CMake/Templates/${RELEASE_CFG_NAME}.in ${CMAKE_BINARY_DIR}/bin/${RELEASE_CFG_NAME})
		endif (CMAKE_BUILD_TYPE STREQUAL "debug")
	endif (WIN32)
endmacro (aml_create_config PREFIX_CFG SUFFIX_CFG)
